<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Java学习,">










<meta name="description" content="摘要：数据的传输即为I/O操作。 按照I/O流动方向，我们分为输入流和输出流。流入内存为输入（Input），流出内存为输出（Output）。 按照数据类型，我们分为字节流和字符流。字节流是以字节为单位，字符流是以字符为单位。">
<meta name="keywords" content="Java学习">
<meta property="og:type" content="article">
<meta property="og:title" content="Java之IO流">
<meta property="og:url" content="/youbaaa.github.io/2018/06/15/Java之IO流/index.html">
<meta property="og:site_name" content="vlsion&#39;手记">
<meta property="og:description" content="摘要：数据的传输即为I/O操作。 按照I/O流动方向，我们分为输入流和输出流。流入内存为输入（Input），流出内存为输出（Output）。 按照数据类型，我们分为字节流和字符流。字节流是以字节为单位，字符流是以字符为单位。">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-08-07T00:18:59.994Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Java之IO流">
<meta name="twitter:description" content="摘要：数据的传输即为I/O操作。 按照I/O流动方向，我们分为输入流和输出流。流入内存为输入（Input），流出内存为输出（Output）。 按照数据类型，我们分为字节流和字符流。字节流是以字节为单位，字符流是以字符为单位。">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="/youbaaa.github.io/2018/06/15/Java之IO流/">





  <title>Java之IO流 | vlsion'手记</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">vlsion'手记</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">擅长Ai、Fw、Fl、Br、Ae、Pr、Id、PS等软件的安装与卸载，精通CSS、JavaScript、PHP、C、C＋＋、java、Ruby、Perl、Lisp、python、Objective-C、ActionScript等单词的拼写，熟悉windows、Linux、Mac、Android、IOS等系统的开关机</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="/youbaaa.github.io/2018/06/15/Java之IO流/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="vlsion_">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/uploads/girl.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="vlsion'手记">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Java之IO流</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-06-15T15:51:51+08:00">
                2018-06-15
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Java中级/" itemprop="url" rel="index">
                    <span itemprop="name">Java中级</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2018/06/15/Java之IO流/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2018/06/15/Java之IO流/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2018/06/15/Java之IO流/" class="leancloud_visitors" data-flag-title="Java之IO流">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>摘要：数据的传输即为I/O操作。</p>
<p>按照I/O流动方向，我们分为输入流和输出流。流入内存为输入（Input），流出内存为输出（Output）。</p>
<p>按照数据类型，我们分为字节流和字符流。字节流是以字节为单位，字符流是以字符为单位。</p>
 <a id="more"></a>

<p>顶级父类如下：</p>
<table>
<thead>
<tr>
<th>-</th>
<th>输入流</th>
<th>输出流</th>
</tr>
</thead>
<tbody><tr>
<td>字节流</td>
<td>InputStream</td>
<td>OutputStream</td>
</tr>
<tr>
<td>字符流</td>
<td>Reader</td>
<td>Writer</td>
</tr>
</tbody></table>
<blockquote>
<p>InputStream定义了字节输入 流的基本共性功能方法。</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">public void close() ：关闭此输入流并释放与此流相关联的任何系统资源。</span><br><span class="line"></span><br><span class="line">public abstract int read() ： 从输入流读取数据的下一个字节。</span><br><span class="line"></span><br><span class="line">public int read(byte[] b) ： 从输入流中读取一些字节数，并将它们存储到字节数组 b中 。</span><br><span class="line"></span><br><span class="line">tips：close方法，当完成流的操作时，必须调用此方法，释放系统资源。</span><br></pre></td></tr></table></figure>

<p>java.io.FileInputStream 类是文件输入流，从文件中读取字节。</p>
<p>构造方法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">FileInputStream(File file) ： 通过打开与实际文件的连接来创建一个 FileInputStream ，该文件由文件系 统中的 File对象 file命名。</span><br><span class="line"></span><br><span class="line">FileInputStream(String name) ： 通过打开与实际文件的连接来创建一个 FileInputStream ，该文件由文件 系统中的路径名 name命名。</span><br></pre></td></tr></table></figure>

<p>当你创建一个流对象时，必须传入一个文件路径。该路径下，如果没有该文件,会抛出 FileNotFoundException 。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">// 使用File对象创建流对象</span><br><span class="line">File file = new File(&quot;a.txt&quot;);</span><br><span class="line">FileInputStream fos = new FileInputStream(file);</span><br><span class="line">// 使用文件名称创建流对象</span><br><span class="line">FileInputStream fos = new FileInputStream(&quot;b.txt&quot;);</span><br></pre></td></tr></table></figure>

<p>读取操作</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">// 定义变量，作为有效个数</span><br><span class="line">int len ；</span><br><span class="line">// 定义字节数组，作为装字节数据的容器</span><br><span class="line">byte[] b = new byte[2];</span><br><span class="line">// 循环读取</span><br><span class="line">while (( len= fis.read(b))!=‐1) &#123;</span><br><span class="line">    // 每次读取后,把数组变成字符串打印</span><br><span class="line">    System.out.println(new String(b,0,len));</span><br><span class="line">    // len 每次读取的有效字节个数</span><br><span class="line">&#125;</span><br><span class="line">// 关闭资源</span><br><span class="line">fis.close();</span><br></pre></td></tr></table></figure>

<blockquote>
<p>OutputStream定义了字 节输出流的基本共性功能方法。</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">public void close() ：关闭此输出流并释放与此流相关联的任何系统资源。</span><br><span class="line"></span><br><span class="line">public void flush() ：刷新此输出流并强制任何缓冲的输出字节被写出。</span><br><span class="line"></span><br><span class="line">public void write(byte[] b) ：将 b.length字节从指定的字节数组写入此输出流。</span><br><span class="line"></span><br><span class="line">public void write(byte[] b, int off, int len) ：从指定的字节数组写入 len字节，从偏移量 off开始输 出到此输出流。</span><br><span class="line"></span><br><span class="line">public abstract void write(int b) ：将指定的字节输出流。</span><br><span class="line"></span><br><span class="line">tips：close方法，当完成流的操作时，必须调用此方法，释放系统资源。</span><br></pre></td></tr></table></figure>

<p>java.io.FileOutputStream 类是文件输出流，用于将数据写出到文件。</p>
<p>构造方法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">public FileOutputStream(File file) ：创建文件输出流以写入由指定的 File对象表示的文件。</span><br><span class="line"></span><br><span class="line">public FileOutputStream(String name) ： 创建文件输出流以指定的名称写入文件。</span><br></pre></td></tr></table></figure>

<p>当你创建一个流对象时，必须传入一个文件路径。该路径下，如果没有这个文件，会创建该文件。如果有这个文 件，会清空这个文件的数据。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">// 使用File对象创建流对象</span><br><span class="line">File file = new File(&quot;a.txt&quot;);</span><br><span class="line">FileOutputStream fos = new FileOutputStream(file);</span><br><span class="line">// 使用文件名称创建流对象</span><br><span class="line">FileOutputStream fos = new FileOutputStream(&quot;b.txt&quot;);</span><br></pre></td></tr></table></figure>

<p>写出操作</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">// 使用文件名称创建流对象</span><br><span class="line">FileOutputStream fos = new FileOutputStream(&quot;fos.txt&quot;);</span><br><span class="line">// 字符串转换为字节数组</span><br><span class="line">byte[] b = &quot;abcde&quot;.getBytes();</span><br><span class="line">// 写出从索引2开始，2个字节。索引2是c，两个字节，也就是cd。</span><br><span class="line">fos.write(b,2,2);</span><br><span class="line">// 关闭资源</span><br><span class="line">fos.close();</span><br></pre></td></tr></table></figure>

<p>数据追加续写</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">public FileOutputStream(File file, boolean append) ： 创建文件输出流以写入由指定的 File对象表示的 文件。</span><br><span class="line"></span><br><span class="line">public FileOutputStream(String name, boolean append) ： 创建文件输出流以指定的名称写入文件。</span><br></pre></td></tr></table></figure>

<blockquote>
<p>Reader字符输入 流的基本共性功能方法。</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">public void close() ：关闭此流并释放与此流相关联的任何系统资源。</span><br><span class="line"></span><br><span class="line">public int read() ： 从输入流读取一个字符。</span><br><span class="line"></span><br><span class="line">public int read(char[] cbuf) ： 从输入流中读取一些字符，并将它们存储到字符数组 cbuf中 。</span><br></pre></td></tr></table></figure>

<p>java.io.FileReader 类是读取字符文件的便利类。构造时使用系统默认的字符编码和默认字节缓冲区。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">// 使用File对象创建流对象</span><br><span class="line">File file = new File(&quot;a.txt&quot;);</span><br><span class="line">FileReader fr = new FileReader(file);</span><br><span class="line">// 使用文件名称创建流对象</span><br><span class="line">FileReader fr = new FileReader(&quot;b.txt&quot;);</span><br></pre></td></tr></table></figure>

<p>读取操作：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">// 定义变量，保存有效字符个数</span><br><span class="line">int len ；</span><br><span class="line">// 定义字符数组，作为装字符数据的容器</span><br><span class="line">char[] cbuf = new char[2];</span><br><span class="line">// 循环读取</span><br><span class="line">while ((len = fr.read(cbuf))!=‐1) &#123;                     </span><br><span class="line">    System.out.println(new String(cbuf,0,len));</span><br><span class="line">&#125;</span><br><span class="line">// 关闭资源</span><br><span class="line">fr.close();</span><br></pre></td></tr></table></figure>

<blockquote>
<p>Writer定义了字节 输出流的基本共性功能方法。</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">void write(int c) 写入单个字符。</span><br><span class="line"></span><br><span class="line">void write(char[] cbuf) 写入字符数组。</span><br><span class="line"></span><br><span class="line">abstract void write(char[] cbuf, int off, int len) 写入字符数组的某一部分,off数组的开始索引,len 写的字符个数。</span><br><span class="line"></span><br><span class="line">void write(String str) 写入字符串。</span><br><span class="line"></span><br><span class="line">void write(String str, int off, int len) 写入字符串的某一部分,off字符串的开始索引,len写的字符个 数。</span><br><span class="line"></span><br><span class="line">void flush() 刷新该流的缓冲。</span><br><span class="line"></span><br><span class="line">void close() 关闭此流，但要先刷新它。</span><br></pre></td></tr></table></figure>

<p>java.io.FileWriter 类是写出字符到文件的便利类。构造时使用系统默认的字符编码和默认字节缓冲区。</p>
<p>构造方法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">FileWriter(File file) ： 创建一个新的 FileWriter，给定要读取的File对象</span><br><span class="line"></span><br><span class="line">FileWriter(String fileName) ： 创建一个新的 FileWriter，给定要读取的文件的名称。</span><br></pre></td></tr></table></figure>

<p>当你创建一个流对象时，必须传入一个文件路径，类似于FileOutputStream。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">// 使用File对象创建流对象</span><br><span class="line">File file = new File(&quot;a.txt&quot;); </span><br><span class="line">FileWriter fw = new FileWriter(file);</span><br><span class="line">// 使用文件名称创建流对象</span><br><span class="line">FileWriter fw = new FileWriter(&quot;b.txt&quot;);</span><br></pre></td></tr></table></figure>

<p>写出操作：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">// 字符串转换为字节数组</span><br><span class="line">char[] chars = &quot;黑马程序员&quot;.toCharArray();</span><br><span class="line">// 写出字符数组</span><br><span class="line">fw.write(chars); // 黑马程序员</span><br><span class="line">// 写出从索引2开始，2个字节。索引2是&apos;程&apos;，两个字节，也就是&apos;程序&apos;。</span><br><span class="line">fw.write(b,2,2); // 程 序</span><br><span class="line">fw.flush();</span><br><span class="line">// 关闭资源</span><br><span class="line">fos.close();</span><br></pre></td></tr></table></figure>

<blockquote>
<p>字节缓冲流</p>
</blockquote>
<p>构造方法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">public BufferedInputStream(InputStream in) ：创建一个 新的缓冲输入流。</span><br><span class="line"></span><br><span class="line">public BufferedOutputStream(OutputStream out) ： 创建一个新的缓冲输出流。</span><br></pre></td></tr></table></figure>

<blockquote>
<p>字符缓冲流</p>
</blockquote>
<p>构造方法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">public BufferedReader(Reader in) ：创建一个 新的缓冲输入流。</span><br><span class="line"></span><br><span class="line">public BufferedWriter(Writer out) ： 创建一个新的缓冲输出流。</span><br></pre></td></tr></table></figure>

<p>特有方法</p>
<p>字符缓冲流的基本方法与普通字符流调用方式一致，不再阐述，我们来看它们具备的特有方法。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">BufferedReader： public String readLine() : 读一行文字。</span><br><span class="line"></span><br><span class="line">BufferedWriter： public void newLine() : 写一行行分隔符,由系统属性定义符号。</span><br></pre></td></tr></table></figure>


      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Java学习/" rel="tag"># Java学习</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/06/11/Java之多线程，线程安全，线程池/" rel="next" title="Java之多线程，线程安全，线程池">
                <i class="fa fa-chevron-left"></i> Java之多线程，线程安全，线程池
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/12/11/数据结构之B树与B-树/" rel="prev" title="数据结构之B树与B+树">
                数据结构之B树与B+树 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/uploads/girl.jpg" alt="vlsion_">
            
              <p class="site-author-name" itemprop="name">vlsion_</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">25</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">10</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">16</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">vlsion_</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  










  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: '9mmqXgbwBLayRV0R9zW2iCxe-gzGzoHsz',
        appKey: 'U0JFc0fpsnrOvTdgoBKRSXwz',
        placeholder: 'Just go go',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("", "");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  

  

  

  

</body>
</html>
